import handleFile from "@util/handleFile"

// 添加拖动事件
function addDrgeEvent(dom: Element, fn: (e: DragEvent) => void) {
  // 1 被拖动的对象进入目标容器
  dom.addEventListener("dragover", e => {
    e.preventDefault();
  }, false);
  // 2  被拖动的对象进入目标容器，释放鼠标键
  dom.addEventListener("drop", (e) => {
    e.preventDefault()
    fn(e as DragEvent)
  }, false);
}

(function initDrgeEvent() {
  addDrgeEvent(document.body, (e: DragEvent) => {
    const fileList = e.dataTransfer?.files
    handleFile(fileList)
  })
}())
